import { menuCreateSchema } from "~/validators/menu";
export default defineEventHandler(async (event) => {
  const result = await runValidate(menuCreateSchema, event);

  const { path } = result.data;
  const menu = await MenuSchema.findOne({ path: path }).lean();
  if (menu) {
    throw createError({
      statusCode: 409,
      statusMessage: "该菜单已存在，请修改后重试",
    });
  }

  const newMenu = await MenuSchema.create(result.data);
  return newMenu;
});
